/**
 * 学生管理API
 */
import { request } from '@/utils/request'

// 学生管理API
export const studentApi = {
  // 获取学生列表
  getStudentList: (params?: any) => {
    return request.get('/students/students/', params)
  },

  // 获取学生详情
  getStudentDetail: (id: number) => {
    return request.get(`/students/students/${id}/`)
  },

  // 创建学生
  createStudent: (data: any) => {
    return request.post('/students/students/', data)
  },

  // 更新学生
  updateStudent: (id: number, data: any) => {
    return request.put(`/students/students/${id}/`, data)
  },

  // 删除学生
  deleteStudent: (id: number) => {
    return request.delete(`/students/students/${id}/`)
  },

  // 重置密码
  resetPassword: (id: number, data: any) => {
    return request.post(`/students/students/${id}/reset_password/`, data)
  },

  // 分配老师
  assignTeacher: (id: number, data: any) => {
    return request.post(`/students/students/${id}/assign_teacher/`, data)
  },

  // 批量操作
  batchOperation: (data: any) => {
    return request.post('/students/students/batch_operation/', data)
  },

  // 批量导入
  importStudents: (data: FormData) => {
    return request.post('/students/students/import_students/', data, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 导出模板
  exportTemplate: () => {
    return request.get('/students/students/export_template/', {
      responseType: 'blob'
    })
  },

  // 获取统计数据
  getStatistics: () => {
    return request.get('/students/students/statistics/')
  },

  // 获取我的学生（老师用）
  getMyStudents: () => {
    return request.get('/students/my-students/')
  },

  // 分配指导老师
  assignAdvisor: (data: any) => {
    return request.post('/students/assign-advisor/', data)
  },

  // 批量分配指导老师
  batchAssignAdvisor: (data: any) => {
    return request.post('/students/batch-assign-advisor/', data)
  },

  // 获取学生简历历史记录
  getStudentResumeHistory: (studentId: number) => {
    return request.get(`/resume-management/students/${studentId}/resume-history/`)
  }
}

// 学校管理API
export const schoolApi = {
  // 获取学校列表
  getSchoolList: (params?: any) => {
    return request.get('/students/schools/', params)
  },

  // 获取学校详情
  getSchoolDetail: (id: number) => {
    return request.get(`/students/schools/${id}/`)
  },

  // 创建学校
  createSchool: (data: any) => {
    return request.post('/students/schools/', data)
  },

  // 更新学校
  updateSchool: (id: number, data: any) => {
    return request.put(`/students/schools/${id}/`, data)
  },

  // 删除学校
  deleteSchool: (id: number) => {
    return request.delete(`/students/schools/${id}/`)
  }
}

// 专业管理API
export const majorApi = {
  // 获取专业列表
  getMajorList: (params?: any) => {
    return request.get('/students/majors/', params)
  },

  // 获取专业详情
  getMajorDetail: (id: number) => {
    return request.get(`/students/majors/${id}/`)
  },

  // 创建专业
  createMajor: (data: any) => {
    return request.post('/students/majors/', data)
  },

  // 更新专业
  updateMajor: (id: number, data: any) => {
    return request.put(`/students/majors/${id}/`, data)
  },

  // 删除专业
  deleteMajor: (id: number) => {
    return request.delete(`/students/majors/${id}/`)
  }
}

// 年级管理API
export const gradeApi = {
  // 获取年级列表
  getGradeList: (params?: any) => {
    return request.get('/students/grades/', params)
  },

  // 获取年级详情
  getGradeDetail: (id: number) => {
    return request.get(`/students/grades/${id}/`)
  },

  // 创建年级
  createGrade: (data: any) => {
    return request.post('/students/grades/', data)
  },

  // 更新年级
  updateGrade: (id: number, data: any) => {
    return request.put(`/students/grades/${id}/`, data)
  },

  // 删除年级
  deleteGrade: (id: number) => {
    return request.delete(`/students/grades/${id}/`)
  }
}

// 班级管理API
export const classApi = {
  // 获取班级列表
  getClassList: (params?: any) => {
    return request.get('/students/classes/', params)
  },

  // 获取班级详情
  getClassDetail: (id: number) => {
    return request.get(`/students/classes/${id}/`)
  },

  // 创建班级
  createClass: (data: any) => {
    return request.post('/students/classes/', data)
  },

  // 更新班级
  updateClass: (id: number, data: any) => {
    return request.put(`/students/classes/${id}/`, data)
  },

  // 删除班级
  deleteClass: (id: number) => {
    return request.delete(`/students/classes/${id}/`)
  }
}

// 教师API
export const teacherApi = {
  // 获取教师列表（用于下拉选择）
  getTeacherList: (params?: any) => {
    return request.get('/students/teachers/', params)
  },

  // 获取教师详情
  getTeacherDetail: (id: number) => {
    return request.get(`/students/teachers/${id}/`)
  }
}

// 师生分配API
export const assignmentApi = {
  // 获取分配列表
  getAssignmentList: (params?: any) => {
    return request.get('/students/assignments/', params)
  },
  
  // 创建分配
  createAssignment: (data: any) => {
    return request.post('/students/assignments/', data)
  },
  
  // 更新分配
  updateAssignment: (id: number, data: any) => {
    return request.put(`/students/assignments/${id}/`, data)
  },
  
  // 删除分配
  deleteAssignment: (id: number) => {
    return request.delete(`/students/assignments/${id}/`)
  }
}

// 导入记录API
export const importRecordApi = {
  // 获取导入记录列表
  getImportRecords: (params?: any) => {
    return request.get('/students/import-records/', params)
  },
  
  // 获取导入记录详情
  getImportRecordDetail: (id: number) => {
    return request.get(`/students/import-records/${id}/`)
  }
}
